import { ColumnGroupType, ColumnType } from "antd/es/table"

import { ICardTablesBaseDetailResponse } from "@/api/business/types"
import { SLink } from "@/components/common"
import { formatHyphen, formatTime, handleNumber, handleNumberColor, statusMap } from "@/utils/util"

const game = (
	newFormat: (arg: string) => string,
	getFromDic: (arg: string, strictlyLabel?: boolean) => any,
	navigate: (to: string, state?: any) => void
): Record<string, ColumnGroupType<any> | ColumnType<any>> => ({
	tableCode: {
		key: "tableCode",
		align: "center",
		dataIndex: "tableCode",
		title: newFormat("dxn.card_ables_list.table_id"),
		width: 180
	},
	tableStatus: {
		key: "status",
		align: "center",
		dataIndex: "status",
		title: newFormat("dxn.card_ables_list.table_state"),
		width: 80,
		render: (text: keyof typeof statusMap) => statusMap[text]
	},
	tableCreatedBy: {
		key: "createdBy",
		align: "center",
		dataIndex: "createdBy",
		title: newFormat("dxn.card_ables_list.creator"),
		width: 80
	},
	tableCreatedAt: {
		key: "createdAt",
		align: "center",
		dataIndex: "createdAt",
		title: newFormat("dxn.card_ables_list.date_time"),
		width: 180,
		render: (text: string) => formatTime(text)
	},
	tableName: {
		key: "tableName",
		align: "center",
		dataIndex: "tableName",
		title: newFormat("dxn.card_ables_list.table_name"),
		width: 100
	},
	gameTypeId: {
		key: "gameTypeId",
		align: "center",
		dataIndex: "gameTypeId",
		title: newFormat("dxn.card_ables_list.game_name"),
		width: 100,
		render: getFromDic("gameTypes", false)
	},
	clubId: {
		key: "clubId",
		align: "center",
		dataIndex: "clubId",
		title: newFormat("dxn.card_ables_list.club_id"),
		width: 100,
		render: (clubId: number) => <SLink onClick={() => navigate(`/dxn/clubManager/clubList?clubId=${clubId}`)}>{clubId}</SLink>
	},
	tableBeginTime: {
		key: "tableBeginTime",
		align: "center",
		dataIndex: "tableBeginTime",
		title: newFormat("dxn.card_ables_list.start_time"),
		width: 180,
		render: (text: string) => formatTime(text)
	},
	tableEndTime: {
		key: "tableEndTime",
		align: "center",
		dataIndex: "tableEndTime",
		title: newFormat("dxn.card_ables_list.end_time"),
		width: 180,
		render: (text: string) => formatTime(text)
	},
	tableType: {
		dataIndex: "tableType",
		title: newFormat("dxn.card_ables_list.blind_injection"),
		width: 120,
		render: (type: number, record: ICardTablesBaseDetailResponse) => {
			if (type === 2002) {
				return record.bbBlindScore
			} else {
				if (record.anteSwitch === 1)
					return formatHyphen(record.sbBlindScore) + "/" + formatHyphen(record.bbBlindScore) + ` (${record.anteScore}) `
				else return formatHyphen(record.sbBlindScore) + "/" + formatHyphen(record.bbBlindScore)
			}
		}
	},
	serviceChargeType: {
		key: "serviceChargeType",
		align: "center",
		dataIndex: "serviceChargeType",
		title: newFormat("dxn.card_ables_list.play_cards_pump_water") + newFormat("dxn.card_ables_list.collection_method"),
		width: 120,
		render: getFromDic("serviceChargeTypeArr", false)
	},
	handCount: {
		key: "handCount",
		align: "center",
		dataIndex: "handCount",
		title: newFormat("dxn.card_ables_list.num_cards_hand"),
		width: 100
	},
	participantTotal: {
		key: "participantTotal",
		align: "center",
		dataIndex: "participantTotal",
		title: newFormat("dxn.card_ables_list.accum_part"),
		width: 100,
		render: (currency: string) => currency || "-"
	},
	onlyDirectMemberSwitch: {
		key: "onlyDirectMemberSwitch",
		align: "center",
		dataIndex: "onlyDirectMemberSwitch",
		title: newFormat("dxn.game_rule.only_direct_member_switch"),
		width: 120,
		render: (text: number, record: ICardTablesBaseDetailResponse) =>
			text === 1
				? record.onlyDirectMember === 1
					? newFormat("common.turn_on")
					: newFormat("dict.entr_authority_type.description")
				: newFormat("dxn.card_ables_list.method_is_not_open")
	},
	bringChipTotal: {
		key: "bringChipTotal",
		align: "center",
		dataIndex: "currency",
		title: newFormat("dxn.card_ables_list.players_bring_in"),
		width: 100,
		render: (currency: string, record: ICardTablesBaseDetailResponse) => handleNumber(currency, record.bringChipTotal.toString())
	},
	afterChipTotal: {
		key: "afterChipTotal",
		align: "center",
		dataIndex: "currency",
		title: newFormat("dxn.card_ables_list.players_bring_out"),
		width: 100,
		render: (currency: string, record: ICardTablesBaseDetailResponse) => handleNumber(currency, record.afterChipTotal.toString())
	},
	pumpingAmountTotal: {
		key: "pumpingAmountTotal",
		align: "center",
		dataIndex: "pumpingAmountTotal",
		title: newFormat("dxn.card_ables_list.play_cards_pump_water"),
		width: 100,
		render: (pumpingAmountTotal: string, record: any) => handleNumber(record.currency, pumpingAmountTotal)
	},
	tableFee: {
		key: "tableFee",
		align: "center",
		dataIndex: "tableFee",
		title: newFormat("dxn.card_ables_list.bureau_service_fee"),
		width: 150,
		render: (tableFee: string, record: any) => handleNumber(record.currency, tableFee)
	},
	insuredNetAmount: {
		key: "insuredNetAmount",
		align: "center",
		dataIndex: "insuredNetAmount",
		title: newFormat("dxn.game_rule.classics_insure"),
		width: 120,
		render: (insuredNetAmount: string, record: any) => (
			<div style={{ color: handleNumberColor(record.insuredNetAmount) }}>{handleNumber(record.currency, insuredNetAmount)}</div>
		)
	},
	costTotal: {
		key: "costTotal",
		align: "center",
		dataIndex: "costTotal",
		title: newFormat("dxn.card_ables_list.total_table_profit_and_loss"),
		width: 120,
		render: (costTotal: string, record: any) => (
			<div style={{ color: handleNumberColor(record.costTotal) }}>{handleNumber(record.currency, costTotal)}</div>
		)
	},
	tableCodePerm: {
		key: "tableCodePerm",
		align: "center",
		dataIndex: "tableCode",
		title: newFormat("dxn.card_ables_list.insurance_information"),
		width: 100,
		render: (tableCode: string) => (
			<SLink onClick={() => navigate(`dxn/insureManager/insureList?tableId=${tableCode}`)}>
				{newFormat("routes.dxn.insure_detail")}
			</SLink>
		)
	}
})

export default game
